import unittest
from Page1 import Page1
from Page2 import Page2
from Page3 import Page3
from selenium import webdriver
import time
from ddt import ddt,file_data
@ddt
class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Edge()
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)

    def tearDown(self):
        time.sleep(3)
        self.driver.quit()

    @file_data('login.yaml')
    def test1_login(self,username,password,exp,des):
        print(f'{username}=={password}=={exp}=={des}')
        po = Page1(self.driver)
        po.geturl('http://localhost:8082/')
        time.sleep(1)
        po.yk_click()  # 点击月考0617
        time.sleep(1)
        po.ul_click()  # 点击用户登录
        time.sleep(1)
        po.send_username(username)  # 输入用户名
        time.sleep(1)
        po.send_password(password)  # 输入密码
        time.sleep(1)
        po.login_click()  # 点击立即登录
        time.sleep(1)
        po.login2_click()  # 点击确定登录
        time.sleep(1)
        self.driver.switch_to.alert.accept()
        if des == '登录成功':
            self.assertEqual(exp, po.gettext(po.dy_custlist))  # add assertion here
        else:
            self.assertTrue(exp == po.gettext(po.dy_userlogin))

    def test2_addcust(self):
        po = Page2(self.driver)
        po.geturl('http://localhost:8082/')
        time.sleep(1)
        po.yk_click()  # 点击月考0617
        time.sleep(1)
        po.cl_click()  # 点击客户列表
        time.sleep(1)
        po.click_addcust()  # 添加客户
        time.sleep(1)
        po.send_custname('莱西奥')  # 输入客户姓名
        time.sleep(1)
        po.send_company('腾讯')  # 输入公司名称
        time.sleep(1)
        po.send_people('小白')  # 输入联系人
        time.sleep(1)
        po.send_email('78495021@qq.com')  # 输入电子邮件
        time.sleep(1)
        po.send_phone('123456789876')  # 输入联系电话
        time.sleep(1)
        po.click_tijiao()  # 点击提交
        time.sleep(1)
        self.driver.switch_to.alert.accept()
        self.assertEqual('客户列表',po.gettext(po.dy_custlist))

    def test3_deletecust(self):
        po = Page3(self.driver)
        po.geturl('http://localhost:8082/')
        time.sleep(1)
        po.yk_click()  # 点击月考0617
        time.sleep(1)
        po.cl_click()  # 点击客户列表
        time.sleep(1)
        po.send_select('莱西奥')  # 输入查询内容
        time.sleep(1)
        po.click_search()  # 点击搜索
        time.sleep(1)
        self.assertIn('莱西',po.gettext(po.dy_name))

if __name__ == '__main__':
    unittest.main()
